package graphix;

import java.awt.Graphics;
import java.util.Vector;
import javax.swing.JPanel;

/**
 * @author duncan
 */
public class DrawPane extends JPanel
{
    private Vector entities = new Vector();

    /**
     * DrawPane constructor.
     */
    public DrawPane()
    {
	
    }

    /**
     * Adds a new Entity to the Pane, and returns it's index.
     *
     * @return The Entites new index.
     */
    public int addEntity(Entity entity)
    {
	entities.addElement(entity);
	return (entities.size() - 1);
    }

    /**
     * Removes the Entity with the specified index.
     */
    public void removeEntity(int index)
    {
	if ((index < 0) || (index >= entities.size()))
	    return;
	entities.removeElementAt(index);
    }

    /**
     * Paints the entities on the pane.
     *
     * @param g The graphics object to draw on.
     */
    public void paint(Graphics g)
    {
	g.clearRect(0, 0, WIDTH, HEIGHT);
	for (int i = 0; i < entities.size(); i++)
	{
	    Entity e = (Entity) entities.get(i);
	    if (e.img == null) 
		continue;
	    g.drawImage(e.img, e.x, e.y, this);
	}
    }
}
